<?php 
namespace app\models;

use yii\db\ActiveRecord;
use Yii;

class report extends ActiveRecord{
     public static function tableName(){
          return "{{%report}}";
   }

     public function add($data){
         if($data){
             date_default_timezone_set('PRC');
             $createtime = date('Y-m-d H:i:s');

            //输入数据库
            $this->openid = $data['openId'];
            $this->nickname = $data['nickname'];
            $this->avatarUrl = $data['avatarUrl'];
            $this->college = $data['college'];
            $this->major = $data['major'];
            $this->time = $createtime;
            $result = $this->save();
            if($result){	
              $error = 0;
	      return $error;
       }else{
              $error = $this->getErrors();
              return $error;
           }
	 }else{
	     $error = 2;
	     return $error;
       }

    }
         
     public function getByOpenId($openId){
         $data = self::find()->select('openid')->where('openid = :openid',[':openid' =>$openId])->asArray()->one();
         return $data;
       }
     
}


